package com.taptech.doufu.ui.view.drawcircle;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.taptech.doufu.bean.TagBean;
import com.taptech.doufu.ui.activity.NovelDetailsActivity;
import com.taptech.doufu.ui.view.choice.ChoiceUtils;
import com.taptech.doufu.util.GlideUtil;
import com.taptech.doufu.util.TTLog;
import com.taptech.doufu.R;
import com.taptech.doufu.ui.activity.NewNovelCreateListTosActivity;
import com.taptech.doufu.bean.HomeTopBean;
import com.taptech.doufu.bean.MineAbstractBean;
import com.taptech.doufu.bean.MineNovelBean;
import com.taptech.doufu.bean.TagsBean;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.listener.HttpResponseListener;
import com.taptech.doufu.services.personalcenter.AccountService;
import com.taptech.doufu.ui.view.personalcenter.ContentTagsViewGroup;
import com.taptech.doufu.ui.view.personalcenter.NewMyCollectView;
import com.taptech.doufu.services.HomeMainServices;
import com.taptech.doufu.util.ColorString;
import com.taptech.doufu.util.DiaobaoUtil;
import com.taptech.doufu.util.TagsUtil;
import com.taptech.doufu.util.UIUtil;
import com.taptech.doufu.net.httputils.HttpResponseObject;

import org.json.JSONObject;

/**
 * Created by lsy on 2015/8/6.
 */
public class NovelRecyclerViewViewHolder extends BaseRecyclerViewViewHolder implements View.OnClickListener {

    Context mContext;
    // 数据
    MineNovelBean bean;
    TextView title;
    ImageView ivPic;
    TextView tvTag1;
    TextView tvTag2;
    TextView tvDesc;
    TextView tvAuthorDesc;
    View lay;


    public NovelRecyclerViewViewHolder(Context context, View convertView) {
        super(context, convertView);
        mContext = context;
        title =  convertView.findViewById(R.id.title);
        ivPic =  convertView.findViewById(R.id.ivPic);
        tvTag1 =  convertView.findViewById(R.id.tvTag1);
        tvTag2 =  convertView.findViewById(R.id.tvTag2);
        tvDesc =  convertView.findViewById(R.id.tvDesc);
        tvAuthorDesc =  convertView.findViewById(R.id.tvAuthorDesc);
        // 全局点击控件
        lay = convertView.findViewById(R.id.lay);
        lay.setOnClickListener(this);
    }

    @Override
    public void setViewHolderChildViewContent(MineAbstractBean tempbean, int position) {
        bean = (MineNovelBean) tempbean;
        mPosition = position;

        if (bean.getTags() != null) {
            if (bean.getTags().length > 0) {
                final TagsBean tag = bean.getTags()[0];
                if (tag != null) {
                    tvTag1.setText(tag.getName());
                    tvTag1.setVisibility(View.VISIBLE);
                    tvTag1.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            ChoiceUtils.jumpTagDetail(mContext,tag.getName());
                        }
                    });
                }else{
                    tvTag1.setVisibility(View.GONE);
                }
            }else{
                tvTag1.setVisibility(View.GONE);
            }
            if (bean.getTags().length > 1) {
                final TagsBean tag = bean.getTags()[1];
                if (tag != null) {
                    tvTag2.setText(tag.getName());
                    tvTag2.setVisibility(View.VISIBLE);
                    tvTag2.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            ChoiceUtils.jumpTagDetail(mContext,tag.getName());
                        }
                    });
                }else{
                    tvTag2.setVisibility(View.GONE);
                }
            }else{
                tvTag2.setVisibility(View.GONE);
            }
        }

        title.setText(bean.getTitle());

        // 作者名
        if (bean.getAuthor() != null && !bean.getAuthor().equals("")) {
            tvAuthorDesc.setText(bean.getAuthor());
        } else {
            tvAuthorDesc.setText("佚名");
        }
        // 简介
        tvDesc.setText(bean.getDes());
        // 上传者图
        String imageUrl = "";

        if (bean.getImages() != null && bean.getImages().length > 0) {
            imageUrl = bean.getImages()[0].getImgUrl();
        }
        GlideUtil.displayImage(ivPic,imageUrl,R.drawable.img_default_loading7);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.lay:
                if (bean != null) {
                    NovelDetailsActivity.Companion.startActivity(mContext, bean.getId(), Intent.FLAG_ACTIVITY_NEW_TASK);
                }
                break;

            default:
                break;
        }
    }


}
